package cn.ocean.org.service.impl;

import cn.ocean.basic.utils.PageList;
import cn.ocean.org.domain.Department;
import cn.ocean.org.mapper.DepartmentMapper;
import cn.ocean.org.query.DepartmentQuery;
import cn.ocean.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {


    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public List<Department> loadAllDep() {
        return departmentMapper.loadAllDep();
    }

    @Override
    public Department getByIdDep(Long id) {
        return departmentMapper.getByIdDep(id);
    }

    @Override
    public void delDep(Long id) {
        departmentMapper.delDep(id);
    }

    @Override
    public void updateDep(Department department) {
        departmentMapper.updateDep(department);
    }

    @Override
    public void addDep(Department department) {
        departmentMapper.addDep(department);
    }

    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {

        // 当前页数据
        List<Department> data = departmentMapper.queryData(departmentQuery);
        // 查询分页总条数
        Integer total = departmentMapper.queryCount(departmentQuery);

        return new PageList<>(total, data)  ;
    }
}
